package cn.skyclass.business
{
	import flash.display.DisplayObject;
	
	import mx.core.ClassFactory;
	
	[DefaultProperty("children")]
	public class MenuItemEx extends MenuItem
	{
		public function MenuItemEx()
		{
			super(null, null);
		}

		public var viewClass:Class;
		public var displayAsPopup:Boolean = false;
		public var popupAsModal:Boolean = false;
		public var popupAsCenter:Boolean = true;
		public var popupX:int;
		public var popupY:int;
		

		private var viewInstance:DisplayObject;

		
		public function getMenuFullPath():String{
			return this.value;
		}
		
		public function getView(createNew:Boolean=false):DisplayObject{
			if((!viewInstance || createNew) && viewClass){
				var f:ClassFactory = new ClassFactory(viewClass);
				viewInstance = f.newInstance();
			}
			return viewInstance;
		}
		
		public function initView(view:DisplayObject):void{
			try{
				var obj:Object = view;
				obj.init();
			}catch(err:Error){}
		}
		
		public function authorize():void{
			if(children){
				for each(var c:MenuItemEx in children){
					c.authorize();
				}
			}
			
			// auth me
		}
		
	}
}


///
// usage:
///
//	<business:MenuItemEx id="menus" name="菜单">
//		<mx:ArrayCollection>
//			<business:MenuItemEx name="我的帐户">
//				<mx:ArrayCollection>
//					<business:MenuItemEx id="miIndex" name="首页" viewClass="{IndexView}" displayAsPopup="false"/>
//					<business:MenuItemEx name="个人信息" viewClass="{MyInfoPop}" displayAsPopup="true"/>
//					<business:MenuItemEx name="修改密码" viewClass="{PasswordView}" displayAsPopup="true"/>
//					<business:MenuItemEx name="使用帮助" viewClass="{HelpViewPop}" displayAsPopup="true"/>
//					<component:LoginMenuItem id="miLogout" name="退出" viewClass="{LoginView}" displayAsPopup="true" 
//						popupAsModal="true"/>
//				</mx:ArrayCollection>
//			</business:MenuItemEx>
//			<business:MenuItemEx id="miBookList" name="我的课本">
//				<mx:ArrayCollection>
//					<business:MenuItemEx name="课本1" viewClass="{BlankView}"/>
//					<business:MenuItemEx name="课本2" viewClass="{BlankView}"/>
//				</mx:ArrayCollection>				
//			</business:MenuItemEx>
//		</mx:ArrayCollection>
//	</business:MenuItemEx>
